package jxcmanager.jxc.controller;


import jxcmanager.jxc.dto.TreeDto;
import jxcmanager.jxc.model.RespBean;
import jxcmanager.jxc.pojo.GoodsType;
import jxcmanager.jxc.service.IGoodsTypeService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 商品类别表 前端控制器
 * </p>
 *
 * @author Yao
 * @since 2022-02-14
 */
@Controller
@RequestMapping("/goodsType")
public class GoodsTypeController {

    @Resource
    private IGoodsTypeService goodsTypeService;

    /**
     * 商品类别首页
     * @return
     */
    @RequestMapping("index")
    public String index(){
        return "goodsType/goods_type";
    }

    @RequestMapping("list")
    @ResponseBody
    public Map<String,Object> goodsTypeList(){
        return goodsTypeService.listGoodsType();
    }

    /**
     * 商品类别添加接口
     * @param pId
     * @param model
     * @return
     */
    @RequestMapping("/addGoodsTypePage")
    public String addGoodsTypePage(Integer pId, Model model) {
        if (pId != null) {
            model.addAttribute("pId", pId);
        }
        return "/goodsType/add";
    }
    /**
     * 商品类别添加
     * @param goodsType
     * @return
     */
    @RequestMapping("save")
    @ResponseBody
    public RespBean saveGoodsType(GoodsType goodsType){
        goodsTypeService.saveGoodsType(goodsType);
        return RespBean.success("商品类别添加成功！");
    }

    /**
     * 商品类别删除
     * @param id
     * @return
     */
    @RequestMapping("delete")
    @ResponseBody
    public RespBean deleteGoodsType(Integer id){
        goodsTypeService.deleteGoodsType(id);
        return RespBean.success("商品类别删除成功！");
    }
    /**
     * 商品类型展示
     * @return
     */
    @ResponseBody
    @RequestMapping("queryAllGoodsTypes")
    public List<TreeDto> queryAllGoodsTypes(Integer typeId){
        return goodsTypeService.queryAllGoodsTypes(typeId);
    }

}
